/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
export var smallestRangeII = function (nums, k) {
  nums.sort((a, b) => a - b)
  let ans = nums[nums.length - 1] - nums[0]
  for (let i = 0; i < nums.length - 1; i++) {
    const max = Math.max(nums[i] + k, nums[nums.length - 1] - k)
    const min = Math.min(nums[0] + k, nums[i + 1] - k)
    console.log(max, min)
    ans = Math.min(ans, max - min)
  }
  return ans
}
